package cn.tedu.sp04orderservice.controller;

import cn.tedu.entity.Item;
import cn.tedu.entity.Order;
import cn.tedu.entity.User;
import cn.tedu.service.OrderService;
import cn.tedu.util.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;

@Slf4j
@RestController
public class orderController {
    @Autowired
    private OrderService orderService;

    //http://localhost:8201/asdaf212radsf
    @GetMapping("/{orderId}")
    public JsonResult<Order> getOrder(@PathVariable String orderId){
        log.warn("获取订单"+orderId);

        Order order = orderService.getOrder(orderId);
        return JsonResult.build().code(200).data(order);
    }

    //http://localhost:8201/
    @GetMapping("/")
    public JsonResult <?>addOrder(){
        log.warn("添加订单成功");

        Order order = new Order();
        order.setId("asdaf212radsf");
        order.setItems(Arrays.asList(new Item[]{
                new Item(1,"aaa",2),
                new Item(2,"bbb",1),
                new Item(3,"ccc",3),
                new Item(4,"ddd",1),
                new Item(5,"eee",5),
        }));

        order.setUser(new User(55, null, null));
        return JsonResult.build().code(200).msg("添加订单成功");
    }

    @GetMapping("/favicon.ico")
    public void ico(){
    }
}
